﻿using AppWebApi.Utilities.SM4;
using Newtonsoft.Json;
using PmSoft.Entity;
using System.Web;

namespace AppWebApi.Models
{

    public class EncryptMess<T> {
        /// <summary>
        /// Sm4加密后的数据
        /// </summary>
        public string Data { get; set; } = string.Empty;

        /// <summary>
        /// 获取加密后的参数
        /// </summary>
        /// <returns></returns>
        public T? GetParame()
        {
            string? encData = HttpUtility.UrlDecode(Sm4Crypto.DecryptCBC(new Sm4Crypto { Data = Data }));
            if (string.IsNullOrEmpty(encData))
                return default;
            return JsonConvert.DeserializeObject<T>(encData);
        }
    }
    public class EncryptMess
    {
        /// <summary>
        /// Sm4加密后的数据
        /// </summary>
        public string Data { get; set; } = string.Empty;


        public WxLoginInfo? GetWxLoginInfo()
        {
            string? encData = HttpUtility.UrlDecode(Sm4Crypto.DecryptCBC(new Sm4Crypto { Data = Data }));
            if (string.IsNullOrEmpty(encData))
                return null;
            return JsonConvert.DeserializeObject<WxLoginInfo>(encData);
        }

        public CaredNoLoginInfo? GetCardLoginInfo()
        {
            string? encData = HttpUtility.UrlDecode(Sm4Crypto.DecryptCBC(new Sm4Crypto { Data = Data }));
            if (string.IsNullOrEmpty(encData))
                return null;
            return JsonConvert.DeserializeObject<CaredNoLoginInfo>(encData);
        }

        public ProjectGroupMemberInfo? GetProjectGroupMemberInfo()
        {
            string? encData = HttpUtility.UrlDecode(Sm4Crypto.DecryptCBC(new Sm4Crypto { Data = Data }));
            if (string.IsNullOrEmpty(encData))
                return null;
            return JsonConvert.DeserializeObject<ProjectGroupMemberInfo>(encData);
        }

        public CheckInInfo? GetCheckInInfo()
        {
            string? encData = HttpUtility.UrlDecode(Sm4Crypto.DecryptCBC(new Sm4Crypto { Data = Data }));
            if (string.IsNullOrEmpty(encData))
                return null;
            return JsonConvert.DeserializeObject<CheckInInfo>(encData);
        }

        public CkeckInDetailInfo? GetCkeckInDetailInfo()
        {
            string? encData = HttpUtility.UrlDecode(Sm4Crypto.DecryptCBC(new Sm4Crypto { Data = Data }));
            if (string.IsNullOrEmpty(encData))
                return null;
            return JsonConvert.DeserializeObject<CkeckInDetailInfo>(encData);
        }
    }

    public class CkeckInDetailInfo
    {
        /// <summary>
        /// 考勤月份 yyyyMM
        /// </summary>
        public string? CheckDate { get; set; }

        /// <summary>
        /// 班组成员id
        /// </summary>
        public int? ProjectGroupMemberId { get; set; }
    }

    public class CheckInInfo
    {
        /// <summary>
        /// 识别记录Id
        /// </summary>
        public string ScanCode { get; set; }
        /// <summary>
        /// 班组成员id
        /// </summary>
        public int? ProjectGroupMemberId { get; set; }
        /// <summary>
        /// WGS84 纬度 
        ///</summary>
        public decimal? Lat { get; set; }
        /// <summary>
        /// WGS84 经度 
        ///</summary>
        public decimal? Lng { get; set; }
    }

    public class ProjectGroupMemberInfo
    {
        /// <summary>
        /// 班组成员id
        /// </summary>
        public int? ProjectGroupMemberId { get; set; }
    }

    public class CaredNoLoginInfo
    {
        /// <summary>
        /// 身份证号
        /// </summary>
        public string? CardNumber { get; set; }

        /// <summary>
        /// 人脸识别代码
        /// </summary>
        public string? ScanCode { get; set; }

        /// <summary>
        /// 登录类型
        /// </summary>
        public UserType? Type { get; set; }
        /// <summary>
        /// 登录密码
        /// </summary>
        public string? PassWord { get; set; }
    }

    public class WxLoginInfo
    {
        /// <summary>
        /// 身份证号
        /// </summary>
        public string? CardNumber { get; set; } = string.Empty;
        /// <summary>
        /// 微信Unionid
        /// </summary>
        public string? Unionid { get; set; } = string.Empty;
        /// <summary>
        /// 微信OpenId
        /// </summary>
        public string? OpenId { get; set; } = string.Empty;

        /// <summary>
        /// 人脸识别代码
        /// </summary>
        public string ScanCode { get; set; }
    }
}
